# -*- coding: utf-8 -*-
"""
# --------------------------------------------------------
# @Author : Pan
# @E-mail : 
# @Date   : 2025-11-03 15:28:15
# @Brief  :
# --------------------------------------------------------
"""
import os
import base64
from pybaseutils import http_utils, json_utils, image_utils, base64_utils

# -*- coding: utf-8 -*-
"""
# --------------------------------------------------------
# @Author : Pan
# @E-mail : 
# @Date   : 2025-09-28 19:25:01
# @Brief  : https://github.com/OpenSQZ/MiniCPM-V-CookBook/blob/main/deployment/vllm/minicpm-v4_5_vllm_zh.md
# --------------------------------------------------------
"""
from openai import OpenAI
from pybaseutils import http_utils, json_utils, image_utils, base64_utils

# API 配置
model = None
# base_url = "http://192.168.68.102:8000/v1"  # vLLM地址 base_url + /chat/completions
base_url = "http://192.168.68.102:40000/v1"  # fastapi 地址 base_url + /chat/completions
api_key = "token-abc123"  # API 密钥需与启动服务时设置的密钥保持一致
video_file = ["../data/video1-frame/image-01.jpg",
              "../data/video1-frame/image-02.jpg",
              "../data/video1-frame/image-03.jpg",
              "../data/video1-frame/image-04.jpg",
              "../data/video1-frame/image-05.jpg",
              "../data/video1-frame/image-06.jpg",
              ]
images = [image_utils.read_image(file, size=(None, 640), use_rgb=True) for file in video_file]
image_info = [{"type": "image_url", "image_url": {"url": image}} for image in images]
messages = [{"role": "user",
             "content": [{"type": "text", "text": "请分析这个视频，描述这个视频中发生的动作行为"}] + image_info,
             "video_metadata": {"fps": 2, 'total_num_frames': len(images)}
             }]
client = OpenAI(api_key=api_key, base_url=base_url)
messages = base64_utils.serialization(messages, prefix="data:image/jpeg;base64,", use_rgb=True)
response = client.chat.completions.create(model=model, messages=messages)
contents = response.choices[0].message.content
print("contents:", contents) if isinstance(contents, str) else print("response:", contents[0]['text'])
